type int = number;
//class IDMap

export class IDMap<T = any> {
  public insert(data: T): int {
    var id = 1;
    // var loc3=0;
    for (var key in this._object) {
      if (!(id <= parseInt(key))) {
        continue;
      }
      id = parseInt(key) + 1;
    }
    this._messagId = id;
    this._object[this._messagId] = data;
    return this._messagId;
  }

  public remove(key: int): boolean {
    if (this._object[key] === undefined) {
      return false;
    }
    delete this._object[key];
    return true;
  }

  public findAndRemove(key: int): T | null {
    if (this._object[key] === undefined) {
      return null;
    }
    var loc1 = this._object[key];
    delete this._object[key];
    return loc1;
  }

  private _messagId: int = 0;

  private _object: Record<int, T> = {};
}
